<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <body>
    <script>
      function getGuangdongCity() {
        const city = [
          {
            name: "shenzhen",
            id: "11",
          },
          {
            name: "guangzhou",
            id: "12",
          },
        ];
        return city;
      }

      let render = function (fn) {
        document.write(JSON.stringify(fn()));
      };

      // 将数据格式更改为 {shenzhen: "11", guangzhou: "12"}， 需要添加适配器模式进行更改
      let addresAdapter = function (oldFn) {
        let obj = {},
          address = oldFn(),
          item;
        for (let i = 0; i < address.length; i++) {
          item = address[i];
          obj[item.name] = item.id;
        }
        return function () {
          return obj;
        };
      };

      render(addresAdapter(getGuangdongCity));
    </script>
  </body>
</html>
